home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
551-575
/
disk_562
/
intuisup
/
library
/
source.lzh
/
libstartup.asm
< prev
next >
Wrap
Assembly Source File
|
1991-07-14
|
8KB
|
354 lines
*************************************
* *
* Intuition Support v2.0 *
* by Torsten Jürgeleit in 05/91 *
* *
* Library startup code *
* *
*************************************
;---------------------------------------------------------------------------
; Includes
;---------------------------------------------------------------------------
NOLIST
INCLUDE <exec/types.i>
INCLUDE <exec/libraries.i>
INCLUDE <exec/initializers.i>
INCLUDE <exec/resident.i>
INCLUDE "libdata.i"
LIST
;---------------------------------------------------------------------------
; External definitions
;---------------------------------------------------------------------------
XDEF .begin
XDEF _LibOpen
XDEF _LibClose
XDEF _LibExpunge
XDEF _LibNull
XDEF _geta4
XDEF _SysBase
XDEF _DosBase
XDEF _GfxBase
XDEF _IntuitionBase
XDEF _LayersBase
;---------------------------------------------------------------------------
; External references
;---------------------------------------------------------------------------
XREF _FuncTable
XREF __H1_org
;---------------------------------------------------------------------------
; Support macros
;---------------------------------------------------------------------------
CALL MACRO
XREF \1
jsr \1
ENDM
CALLSYS MACRO
XREF _LVO\1
jsr _LVO\1(a6)
ENDM
PUSH MACRO
movem.l \1,-(sp)
ENDM
PULL MACRO
movem.l (sp)+,\1
ENDM
;---------------------------------------------------------------------------
; First executable location -> do nothing
;---------------------------------------------------------------------------
SECTION IntuitionSupport,CODE
.begin:
moveq #0,d0
rts
;---------------------------------------------------------------------------
; RomTag structure
;---------------------------------------------------------------------------
RomTag: ; STRUCTURE RT,0
dc.w RTC_MATCHWORD ; UWORD RT_MATCHWORD
dc.l RomTag ; APTR RT_MATCHTAG
dc.l EndCode ; APTR RT_ENDSKIP
dc.b RTF_AUTOINIT ; UBYTE RT_FLAGS
dc.b VERSION ; UBYTE RT_VERSION
dc.b NT_LIBRARY ; UBYTE RT_TYPE
dc.b PRIORITY ; BYTE RT_PRI
dc.l LibName ; APTR RT_NAME
dc.l LibID ; APTR RT_IDSTRING
dc.l InitTable ; APTR RT_INIT
;---------------------------------------------------------------------------
; Library strings
;---------------------------------------------------------------------------
LibName: LIB_NAME
LibTag: dc.b 0,"$VER: "
LibID: LIB_ID
INCLUDE <compile_date.i>
DosName: dc.b "dos.library",0
GfxName: dc.b "graphics.library",0
IntuitionName: dc.b "intuition.library",0
LayersName: dc.b "layers.library",0
EVEN
;---------------------------------------------------------------------------
; Library tables
;---------------------------------------------------------------------------
InitTable:
dc.l LIB_SIZEOF ; size of library base data space
dc.l _FuncTable ; pointer to function initializers
dc.l DataTable ; pointer to data initializers
dc.l InitRoutine ; routine to run
DataTable:
INITBYTE LN_TYPE,NT_LIBRARY
INITLONG LN_NAME,LibName
INITBYTE LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
INITWORD LIB_VERSION,VERSION
INITWORD LIB_REVISION,REVISION
INITLONG LIB_IDSTRING,LibID
dc.l 0
;---------------------------------------------------------------------------
; Library init routine
;
; Input: d0 = library ptr Return: d0 = library ptr or NULL if error
; a0 = seglist ptr
; a6 = SysBase
;---------------------------------------------------------------------------
InitRoutine:
PUSH d2/a2-a3
; --- save library ptr
move.l d0,a2
; --- init important ptrs
lea SegList(pc),a3 ; a3 := start of ptr buffer
move.l a0,(a3)+ ; init SegList
move.l a6,(a3)+ ; init _SysBase
; --- open libraries
lea DosName(pc),a1
moveq #0,d0
CALLSYS OpenLibrary
move.l d0,(a3)+
beq InitRoutine_Error
lea GfxName(pc),a1
moveq #0,d0
CALLSYS OpenLibrary
move.l d0,(a3)+
beq InitRoutine_CloseDosLib
lea IntuitionName(pc),a1
moveq #0,d0
CALLSYS OpenLibrary
move.l d0,(a3)+
beq InitRoutine_CloseGfxLib
lea LayersName(pc),a1
moveq #0,d0
CALLSYS OpenLibrary
move.l d0,(a3)+
beq InitRoutine_CloseGfxLib
; --- call library specific init routine
PUSH a2-a4/a6
bsr _geta4
CALL _LibInit
PULL a2-a4/a6
tst.w d0 ; check return code (BOOL)
beq InitRoutine_CloseIntuitionLib
move.l a2,d0 ; set return code -> ok
InitRoutine_Exit:
PULL d2/a2-a3
rts
InitRoutine_CloseLayersLib:
moveq #3,d2
bra InitRoutine_CloseLibs
InitRoutine_CloseIntuitionLib:
moveq #2,d2
bra InitRoutine_CloseLibs
InitRoutine_CloseGfxLib:
moveq #1,d2
bra InitRoutine_CloseLibs
InitRoutine_CloseDosLib:
moveq #0,d2
InitRoutine_CloseLibs:
move.l -(a3),a1
CALLSYS CloseLibrary
dbra d2,InitRoutine_CloseLibs
InitRoutine_Error:
moveq #0,d0 ; set return code -> error
bra InitRoutine_Exit
;---------------------------------------------------------------------------
; Library open routine
;
; Input: d0 = version Return: d0 = library ptr or NULL if error
; a6 = library ptr
;---------------------------------------------------------------------------
_LibOpen:
; --- mark us as having another opener
addq.w #1,LIB_OPENCNT(a6)
; --- prevent delayed expunges
bclr #LIBB_DELEXP,LIB_FLAGS(a6)
move.l a6,d0 ; set return code -> ok
rts
;---------------------------------------------------------------------------
; Library close routine
;
; Input: a6 = library ptr Return: d0 = NULL or seglist ptr if expunge
;---------------------------------------------------------------------------
_LibClose:
; --- set the return value for no expunge
moveq #0,d0
; --- mark us as having one fewer openers
subq.w #1,LIB_OPENCNT(a6)
; --- see if there is anyone left with us open
bne.s LibClose_Exit
; --- see if we have a delayed expunge pending
btst #LIBB_DELEXP,LIB_FLAGS(a6)
beq.s LibClose_Exit
; --- do the expunge
bsr _LibExpunge
LibClose_Exit:
rts
;---------------------------------------------------------------------------
; Library open routine
;
; Input: a6 = library ptr Return: d0 = NULL or seglist ptr if expunge
;---------------------------------------------------------------------------
_LibExpunge:
PUSH d2/a5-a6
; --- init some regs
move.l a6,a5 ; a5 := library ptr
move.l _SysBase(pc),a6 ; a6 := SysBase
; --- see if anyone has us open
tst.w LIB_OPENCNT(a5)
beq LibExpunge_DoExpunge
; --- it is still open. set the delayed expunge flag
bset #LIBB_DELEXP,LIB_FLAGS(a5)
moveq #0,d0 ; set reurn code -> no expunge
bra.s LibExpunge_Exit
LibExpunge_DoExpunge:
; --- unlink from library list
move.l a5,a1
CALLSYS Remove
; --- library specific expunge routine
PUSH a4/a6
bsr _geta4
CALL _LibFree
PULL a4/a6
; --- free our memory
moveq #0,d0
move.l a5,a1
move.w LIB_NEGSIZE(a5),d0
sub.l d0,a1
add.w LIB_POSSIZE(a5),d0
CALLSYS FreeMem
; --- close libraries
lea _DosBase(pc),a5
moveq #3,d2
LibExpunge_CloseLoop:
move.l (a5)+,a1
CALLSYS CloseLibrary
dbra d2,LibExpunge_CloseLoop
; --- set up our return value
move.l SegList(pc),d0
LibExpunge_Exit:
PULL d2/a5-a6
rts
;---------------------------------------------------------------------------
; Library null routine
;
; Input: a6 = library ptr
;---------------------------------------------------------------------------
_LibNull:
moveq #0,d0
rts
;---------------------------------------------------------------------------
; Init data segment ptr a4 - needed for small data memory model
;---------------------------------------------------------------------------
_geta4:
FAR CODE
FAR DATA
lea __H1_org+32766,a4
NEAR DATA
NEAR CODE
rts
;---------------------------------------------------------------------------
; Important ptrs -> init by Init
;---------------------------------------------------------------------------
SegList:
dc.l 0
_SysBase:
dc.l 0
_DosBase:
dc.l 0
_GfxBase:
dc.l 0
_IntuitionBase:
dc.l 0
_LayersBase:
dc.l 0
;---------------------------------------------------------------------------
; Skip label for RomTag
;---------------------------------------------------------------------------
EndCode:
END